var Web3 = require("web3");
// 创建web3对象
var web3 = new Web3();
// 连接到以太坊节点
web3.setProvider(new Web3.providers.HttpProvider("http://192.168.1.89:8545"));
var abi = [{
    "constant": true,
    "inputs": [],
    "name": "name",
    "outputs": [{"name": "", "type": "string"}],
    "payable": false,
    "stateMutability": "view",
    "type": "function"
}, {
    "constant": true,
    "inputs": [],
    "name": "decimals",
    "outputs": [{"name": "", "type": "uint8"}],
    "payable": false,
    "stateMutability": "view",
    "type": "function"
}, {
    "constant": true,
    "inputs": [{"name": "", "type": "address"}],
    "name": "balanceOf",
    "outputs": [{"name": "", "type": "uint256"}],
    "payable": false,
    "stateMutability": "view",
    "type": "function"
}, {
    "constant": true,
    "inputs": [],
    "name": "symbol",
    "outputs": [{"name": "", "type": "string"}],
    "payable": false,
    "stateMutability": "view",
    "type": "function"
}, {
    "constant": false,
    "inputs": [{"name": "_to", "type": "address"}, {"name": "_value", "type": "uint256"}],
    "name": "transfer",
    "outputs": [],
    "payable": false,
    "stateMutability": "nonpayable",
    "type": "function"
}, {
    "inputs": [{"name": "_supply", "type": "uint256"}, {"name": "_name", "type": "string"}, {
        "name": "_symbol",
        "type": "string"
    }, {"name": "_decimals", "type": "uint8"}, {"name": "owner", "type": "address"}],
    "payable": false,
    "stateMutability": "nonpayable",
    "type": "constructor"
}, {
    "anonymous": false,
    "inputs": [{"indexed": true, "name": "from", "type": "address"}, {
        "indexed": true,
        "name": "to",
        "type": "address"
    }, {"indexed": false, "name": "value", "type": "uint256"}],
    "name": "Transfer",
    "type": "event"
}];

var contractAddress = "0x8c3e9a7fdd64cd90c05ec1dc57fdbe20a127e354";
// contractAddress="0xb2fbc292f4b500e86cda8beb142ee4066ce803f7"
var contract = web3.eth.contract(abi).at(contractAddress);
console.log(contract.address)
console.log(contract.name.call())
console.log(contract.decimals.call().toNumber())
// console.log("帐户" + contract.balanceOf("0x461b56c9bd70ee2a78c89d8d8ebd76ce947b6b86").toNumber())
// var from = web3.eth.accounts[1];
// var to = web3.eth.accounts[0];
// console.log("转帐后帐户From" + contract.balanceOf(from).toNumber())
// console.log("转帐后帐户To" + contract.balanceOf(to).toNumber())

// contract.totalSupply.call(function (err, totalSupply) {
//     console.log(totalSupply)

    // 2. get the number of decimal places used to represent this token

    // contract.decimals.call(function (err, decimals) {
    //
    //     // 3. get the name of the token
    //
    //     contract.name.call(function (err, name) {
    //
    //         // 3. get the balance of the account holder
    //
    //         var accountAddress = $('#accountAddress').val();
    //
    //         token.balanceOf.call(accountAddress, function (err, balance) {
    //
    //
    //         });
    //
    //     });
    //
    // });

// });